package edu.ccut.saturn.component.loader.data;

import java.util.List;

import org.dom4j.Element;

import edu.ccut.saturn.component.ISaturnDataSqlItemInfo;
import edu.ccut.saturn.component.impl.sql.DynamicItemInfo;

public class DynamicElementLoader extends AbstractSqlItemInfoLoader {

	@SuppressWarnings("unchecked")
	@Override
	public ISaturnDataSqlItemInfo loadSqlItemInfo(Object element)
			throws Exception {

		String prepend = ((Element) element).attributeValue(NODE_KEY_PREPEND);
		DynamicItemInfo dynamicItem = new DynamicItemInfo(prepend);

		if (((Element) element).content().size() > 0) {
			List<ISaturnDataSqlItemInfo> sqlItemInfos = getSqlItemInfos(((Element) element)
					.content());

			dynamicItem.setSubSqlItemInfos(sqlItemInfos);
		}
		return dynamicItem;
	}
}
